package com.example.helloworld

import android.annotation.SuppressLint
import android.os.Bundle
import android.os.PersistableBundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.ComponentActivity

class MyActivity  : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_layout)
        val textView = findViewById<TextView>(R.id.textView4)
        val button = findViewById<Button>(R.id.button3)
        val imageView=findViewById<ImageView>(R.id.imageView)
        textView.text=getString(R.string.textView)
        button.setOnClickListener {
            textView.text = getString(R.string.click_me)
        }
    }
}

//class MyActivity  : ComponentActivity() {
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        //创建一个LinearLayout
//        val linearLayout = LinearLayout(this)
//        linearLayout.orientation = LinearLayout.VERTICAL
//
//        //创建TextView
//        val textView=TextView(this)
//        textView.layoutParams= ViewGroup.LayoutParams(
//            ViewGroup.LayoutParams.MATCH_PARENT,
//            ViewGroup.LayoutParams.WRAP_CONTENT
//        )
//        textView.textSize=48f
//        textView.text = getString(R.string.textView)
//
//        //添加TextView
//        linearLayout.addView(textView)
//
//        //创建Button
//        val button= Button(this)
//        button.layoutParams= ViewGroup.LayoutParams(
//            ViewGroup.LayoutParams.MATCH_PARENT,
//            ViewGroup.LayoutParams.WRAP_CONTENT
//        )
//        button.text=getString(R.string.button)
//
//        //添加Button
//        linearLayout.addView(button)
//
//        //设置整个布局
//        setContentView(linearLayout)
//
//        button.setOnClickListener{
//            textView.text="I am clicked again!"
//        }
//    }
//
//}